<?php
namespace backend\controllers;

use bc\controller\BackendController;
use bc\util\Uploader;

class UeditorController extends BackendController
{
	
	public function actionIndex()
	{
		$this->layout = false;
		return $this->render('index');
	}
	
	public function actionSub()
	{
		print_r($_POST);
		exit;
	}
	
	
	public function actionUpload()
	{
		error_reporting( E_ERROR | E_WARNING );
		$this->layout = false;
		//上传文件目录
		$path = UPLOAD_PATH . 'upload/';
		//上传配置
		$config = array(
				"savePath" => $path ,             //存储文件夹
				"maxSize" => 1000 ,                   //允许的文件最大尺寸，单位KB
				"allowFiles" => array( ".gif" , ".png" , ".jpg" , ".jpeg" , ".bmp" )  //允许的文件格式
		);
		
		
		//背景保存在临时目录中
		$config[ "savePath" ] = $path;
		$up = new Uploader( "upfile" , $config );
		$callback=$_GET['callback'];
		
		$info = $up->getFileInfo();
		
		//modify by guoxiaoyong   info[url]有些小技巧
		$info['url'] = str_replace($path, '', $info['url']);
				
		/**
		 * 返回数据
		*/
		if($callback) {
			echo '<script>'.$callback.'('.json_encode($info).')</script>';
		} else {
			echo json_encode($info);
		}
		
	}
	
}

